package com.myj.jim.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.myj.jim.dao.ArticleDao;
import com.myj.jim.domain.Article;
import com.myj.jim.domain.bootstraptable.BootstrapTable;
import com.myj.jim.domain.bootstraptable.BootstrapTableJSON;
import com.myj.jim.service.ArticleService;
import com.myj.jim.util.BootstrapTableUtil;

@Service
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleDao articleDao;
	
	@Override
	public BootstrapTableJSON findPage(Map<String,Object> map) {
		int total = articleDao.count(map);
		List<Article> list = articleDao.findPage(map);
		
		return BootstrapTableUtil.initBtj(list, total);
	}

	@Override
	public boolean save(Article article) {
		return articleDao.insert(article)!=0;
	}

	@Override
	public Article getArticleById(Integer id) {
		return articleDao.selectByPrimaryKey(id);
	}

	@Override
	public boolean update(Article article) {
		return articleDao.updateByPrimaryKeyWithBLOBs(article)!=0;
	}

	@Override
	public boolean delete(Integer id) {
		return articleDao.deleteByPrimaryKey(id)!=0;
	}

}
